import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from '/src/router/index.js'
import store from '/src/store'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css';
import panelHead from "./components/panelHead.vue";
const localData = localStorage.getItem("pz_v3pz")
if(localData){
    store.commit('dynamicMenu',JSON.parse(localData).menu.routerList)
    store.state.menu.routerList.forEach(item=>{
        router.addRoute("main",item)
    })
}
router.beforeEach((to,from)=>{
    //非登录页面token不存在
    const token = localStorage.getItem('pz_token')
    if(!token && to.path!=='/login'){
        return '/login'
    }else if(token&&to.path==='/login'){
        return '/'
    }else{
        return true
    }
})
// createApp(App).mount('#app')
const app = createApp(App)
app.use(ElementPlus)
for(const [key,component] of Object.entries(ElementPlusIconsVue)){
    app.component(key,component)
}
app.use(router)
app.use(store)
app.component('panelHead',panelHead)
app.mount("#app")